Revert "Be compatible with the stdlib for now ('static shell)"
authorBrian Koropoff <bkoropoff@gmail.com>
Fri, 5 Sep 2014 07:18:44 +0000 (00:18 -0700)
committerBrian Koropoff <bkoropoff@gmail.com>
Fri, 5 Sep 2014 07:18:44 +0000 (00:18 -0700)
This reverts commit a601d049feff5768b0d99b9fcec807b277fa4c81.

src/cargo/core/shell.rs
src/cargo/lib.rs
src/cargo/ops/cargo_compile.rs
src/cargo/util/config.rs
tests/test_cargo_cross_compile.rs
tests/test_shell.rs

index 4778929a1981deb6a18b6cc49eb962fc5c5c6c10..9c741e1ab1ff477191871531ae38f85a207f907e 100644 (file)
@@ -10,34 +10,34 @@ pub struct ShellConfig {
     pub tty: bool
 }
 
-enum AdequateTerminal {
-    NoColor(Box<Writer+'static>),
-    Color(Box<Terminal<Box<Writer+'static>>+'static>)
+enum AdequateTerminal<'a> {
+    NoColor(Box<Writer+'a>),
+    Color(Box<Terminal<Box<Writer+'a>>+'a>)
 }
 
-pub struct Shell {
-    terminal: AdequateTerminal,
+pub struct Shell<'a> {
+    terminal: AdequateTerminal<'a>,
     config: ShellConfig
 }
 
-pub struct MultiShell {
-    out: Shell,
-    err: Shell,
+pub struct MultiShell<'a> {
+    out: Shell<'a>,
+    err: Shell<'a>,
     verbose: bool
 }
 
 pub type Callback<'a> = |&mut MultiShell|:'a -> IoResult<()>;
 
-impl MultiShell {
-    pub fn new(out: Shell, err: Shell, verbose: bool) -> MultiShell {
+impl<'a> MultiShell<'a> {
+    pub fn new(out: Shell<'a>, err: Shell<'a>, verbose: bool) -> MultiShell<'a> {
         MultiShell { out: out, err: err, verbose: verbose }
     }
 
-    pub fn out(&mut self) -> &mut Shell {
+    pub fn out(&mut self) -> &mut Shell<'a> {
         &mut self.out
     }
 
-    pub fn err(&mut self) -> &mut Shell {
+    pub fn err(&mut self) -> &mut Shell<'a> {
         &mut self.err
     }
 
@@ -72,17 +72,17 @@ impl MultiShell {
     }
 }
 
-pub type ShellCallback<'a> = |&mut Shell|:'a -> IoResult<()>;
+pub type ShellCallback<'a> = |&mut Shell<'a>|:'a -> IoResult<()>;
 
-impl Shell {
-    pub fn create(out: Box<Writer+'static>, config: ShellConfig) -> Shell {
+impl<'a> Shell<'a> {
+    pub fn create(out: Box<Writer+'a>, config: ShellConfig) -> Shell<'a> {
         if config.tty && config.color {
-            let term: Option<term::TerminfoTerminal<Box<Writer+'static>>> = Terminal::new(out);
+            let term: Option<term::TerminfoTerminal<Box<Writer+'a>>> = Terminal::new(out);
             term.map(|t| Shell {
-                terminal: Color(box t as Box<Terminal<Box<Writer+'static>>>),
+                terminal: Color(box t as Box<Terminal<Box<Writer+'a>>>),
                 config: config
             }).unwrap_or_else(|| {
-                Shell { terminal: NoColor(box stderr() as Box<Writer+'static>), config: config }
+                Shell { terminal: NoColor(box stderr() as Box<Writer+'a>), config: config }
             })
         } else {
             Shell { terminal: NoColor(out), config: config }
@@ -121,8 +121,8 @@ impl Shell {
     }
 }
 
-impl Terminal<Box<Writer+'static>> for Shell {
-    fn new(out: Box<Writer+'static>) -> Option<Shell> {
+impl<'a> Terminal<Box<Writer+'a>> for Shell<'a> {
+    fn new(out: Box<Writer+'a>) -> Option<Shell<'a>> {
         Some(Shell {
             terminal: NoColor(out),
             config: ShellConfig {
@@ -168,18 +168,18 @@ impl Terminal<Box<Writer+'static>> for Shell {
         }
     }
 
-    fn unwrap(self) -> Box<Writer+'static> {
+    fn unwrap(self) -> Box<Writer+'a> {
         fail!("Can't unwrap a Shell");
     }
 
-    fn get_ref<'b>(&'b self) -> &'b Box<Writer+'static> {
+    fn get_ref<'b>(&'b self) -> &'b Box<Writer+'a> {
         match self.terminal {
             Color(ref c) => c.get_ref(),
             NoColor(ref w) => w
         }
     }
 
-    fn get_mut<'b>(&'b mut self) -> &'b mut Box<Writer+'static> {
+    fn get_mut<'b>(&'b mut self) -> &'b mut Box<Writer+'a> {
         match self.terminal {
             Color(ref mut c) => c.get_mut(),
             NoColor(ref mut w) => w
@@ -187,7 +187,7 @@ impl Terminal<Box<Writer+'static>> for Shell {
     }
 }
 
-impl Writer for Shell {
+impl<'a> Writer for Shell<'a> {
     fn write(&mut self, buf: &[u8]) -> IoResult<()> {
         match self.terminal {
             Color(ref mut c) => c.write(buf),
index 8144eb39666a24dd5b364f5138b055558d8822e8..f01277bb4bfc3d2210ea13c67957e8bc11b6be62 100644 (file)
@@ -150,7 +150,7 @@ pub fn process_executed<'a,
     }
 }
 
-pub fn shell(verbose: bool) -> MultiShell {
+pub fn shell(verbose: bool) -> MultiShell<'static> {
     let tty = stderr_raw().isatty();
     let stderr = box stderr() as Box<Writer>;
 
index 903ba99cad63c97fe50dafee65910e43f01c9160..0c437b777353445d01a40ee770a59c48fd5ee0db 100644 (file)
@@ -36,7 +36,7 @@ use util::{CargoResult, Wrap, config, internal, human, ChainError, profile};
 pub struct CompileOptions<'a> {
     pub update: bool,
     pub env: &'a str,
-    pub shell: &'a mut MultiShell,
+    pub shell: &'a mut MultiShell<'a>,
     pub jobs: Option<uint>,
     pub target: Option<&'a str>,
     pub dev_deps: bool,
index cf1cf419e20d2c49d16cd28d170518177f203f67..eb3ad0aca79c1aedef72d4abcb7d9eefd86e930a 100644 (file)
@@ -9,7 +9,7 @@ use util::toml as cargo_toml;
 
 pub struct Config<'a> {
     home_path: Path,
-    shell: &'a mut MultiShell,
+    shell: &'a mut MultiShell<'a>,
     jobs: uint,
     target: Option<String>,
     linker: Option<String>,
index 13c1c6663a414b19b3753c3413c0e8925c176d3f..1dabc64ff0a04cdc31df26ccdaa7f814deef6062 100644 (file)
@@ -163,7 +163,7 @@ test!(plugin_deps {
             }
 
             fn expand_bar(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree])
-                          -> Box<MacResult + 'static> {
+                          -> Box<MacResult> {
                 MacExpr::new(quote_expr!(cx, 1i))
             }
         "#);
@@ -245,7 +245,7 @@ test!(plugin_to_the_max {
             }
 
             fn expand_bar(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree])
-                          -> Box<MacResult + 'static> {
+                          -> Box<MacResult> {
                 MacExpr::new(quote_expr!(cx, baz::baz()))
             }
         "#);
index f0da10669f1d3cbf68a65e6004dec6dd68688383..d1211ab2bacbe54109c6ea1b6ffda92cce0fe2dd 100644 (file)
@@ -1,55 +1,50 @@
-use std::io::{MemWriter, IoResult, ChanReader, ChanWriter};
-
-use term::{Terminal, TerminfoTerminal, color};
+use support::{ResultTest,Tap,shell_writes};
 use hamcrest::{assert_that};
-
-use support::{ResultTest, Tap, shell_writes};
+use std::io::{MemWriter, BufWriter, IoResult};
 use cargo::core::shell::{Shell,ShellConfig};
+use term::{Terminal,TerminfoTerminal,color};
 
 fn setup() {
 }
 
-fn io_channel() -> (Box<Writer + 'static>, Box<Reader + 'static>) {
-    let (tx, rx) = channel();
-    (box ChanWriter::new(tx), box ChanReader::new(rx))
+fn writer(buf: &mut [u8]) -> Box<Writer> {
+    box BufWriter::new(buf) as Box<Writer>
 }
 
 test!(non_tty {
     let config = ShellConfig { color: true, verbose: true, tty: false };
-    let (tx, mut rx) = io_channel();
+    let mut buf: Vec<u8> = Vec::from_elem(9, 0 as u8);
 
-    Shell::create(tx, config).tap(|shell| {
+    Shell::create(writer(buf.as_mut_slice()), config).tap(|shell| {
         shell.say("Hey Alex", color::RED).assert();
+        assert_that(buf.as_slice(), shell_writes("Hey Alex\n"));
     });
-    assert_that(rx.read_to_end().unwrap().as_slice(),
-                shell_writes("Hey Alex\n"));
 })
 
 test!(color_explicitly_disabled {
     let config = ShellConfig { color: false, verbose: true, tty: true };
-    let (tx, mut rx) = io_channel();
+    let mut buf: Vec<u8> = Vec::from_elem(9, 0 as u8);
 
-    Shell::create(tx, config).tap(|shell| {
+    Shell::create(writer(buf.as_mut_slice()), config).tap(|shell| {
         shell.say("Hey Alex", color::RED).assert();
+        assert_that(buf.as_slice(), shell_writes("Hey Alex\n"));
     });
-    assert_that(rx.read_to_end().unwrap().as_slice(),
-                shell_writes("Hey Alex\n"));
 })
 
 test!(colored_shell {
     let term: Option<TerminfoTerminal<MemWriter>> =
         Terminal::new(MemWriter::new());
     if term.is_none() { return }
-    let (tx, mut rx) = io_channel();
 
     let config = ShellConfig { color: true, verbose: true, tty: true };
+    let mut buf: Vec<u8> = Vec::from_elem(100, 0 as u8);
 
-    Shell::create(tx, config).tap(|shell| {
+    Shell::create(writer(buf.as_mut_slice()), config).tap(|shell| {
         shell.say("Hey Alex", color::RED).assert();
+        let buf = buf.as_slice().slice_to(buf.iter().position(|a| *a == 0).unwrap());
+        assert_that(buf, shell_writes(colored_output("Hey Alex\n",
+                                                     color::RED).assert()));
     });
-    assert_that(rx.read_to_end().unwrap().as_slice(),
-                shell_writes(colored_output("Hey Alex\n",
-                                            color::RED).assert()));
 })
 
 fn colored_output<S: Str>(string: S, color: color::Color) -> IoResult<String> {